<template>
	<view class="pages">
		<u-sticky bgColor="#fff" height="60">
			<u-tabs :list="list" lineWidth="30" activeStyle="color: #4ca0fd" itemStyle="padding:0 25px;height: 35px;"
				@click="click"></u-tabs>
		</u-sticky>

		<template v-if="shopList.length != 0">
			<view class="availabilityList" v-for="(itemshop,indexshop) in shopList" :key="indexshop">

				<view class="shopList">
					<u--image :src="itemshop.media_url || '../../static/default/img_404.jpg'" width="100px"
						height="100px" radius="5" @click="detail(itemshop)"></u--image>
					<view class="description">
						<view class="title">
							<view class="description_title">
								{{itemshop.name}}
							</view>
							<view class="titleType primary " v-if="index == 0">
								未确认
							</view>

							<view class="titleType success" v-if="index == 1">
								已确认
							</view>
							<view class="titleType success" v-if="index == 2">
								已取消
							</view>
							<view class="titleType error" v-if="index == 3">
								已拒绝
							</view>
						</view>
						<view class="description_squaremetre">
							<!-- {{ itemshop.housetitle }}|{{itemshop.acreage}}m² -->
							{{ itemshop.tenant_name }}
						</view>
						<view class="description_squaremetre">
							<!-- {{ itemshop.housetitle }}|{{itemshop.acreage}}m² -->
							{{ itemshop.housetitle }}
						</view>
						<!-- 	<view class="button_row">
							<view class="button_1" v-for="(tagItem, tagIndex) of changeList(itemshop.labels)"
								:key="tagIndex">
								{{tagItem}}
							</view>
					 
						</view> -->
						<view class="row">
							<view class="money">
								{{itemshop.rent}}
								<view class="unit">
									元/月
								</view>
							</view>

							<view class="button_row">
								<u-button type="primary" size="small" color="rgb(245, 110, 61)" text="联系房东"
									v-if="index==0" @click="callAgent(itemshop)"></u-button>
								<u-button type="primary" size="small" color="rgb(245, 110, 61)" text="再次申请"
									v-if="index==3" @click="application(itemshop)"></u-button>
								<u-button size="small" text="取消" v-if="index==3" style="margin-left: 10rpx;"
									@click="clanceMethod(itemshop)"></u-button>
							</view>


						</view>
					</view>
				</view>
			</view>
		</template>
		<view class="" v-else>
			<u-empty icon="https://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<u-popup :show="show" mode="center" :round="10" @close="show = false">
			<view class="popup">
				<view class="cue">
					<!-- 拨打{{itemshop.tenantPhone}} -->
				</view>
				<view class="button_box">
					<u-button color="#f05a23" class="sure" @tap="showDetermine">确定</u-button>
					<u-button @click="show = false">取消</u-button>
				</view>
			</view>
		</u-popup>
		<u-modal :show="showModal" :title="title" :content='content' :showCancelButton="true"
			@cancel="showModal = false" @confirm="confirm"></u-modal>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		agentgetConfirm
	} from "@/api/home/index.js"
	import {
		putLease
	} from "@/api/lease/index.js"
	import {
		getUnreadNum,
		haveRead
	} from "@/api/my/index.js"
	export default {
		data() {
			return {
				index: 0,
				showModal: false,
				show: false,
				title: '提示',
				content: '确定取消吗?',
				list: [
					{
						name: '未确认',
					}, {
						name: '已确认',
						badge: {
							value: 0,
						}
					},
					{
						name: '已取消',
					}, {
						name: '已拒绝',
						badge: {
							value: 0,
						}
					}
				],
				labelsColor: ['#3c9cff', '#f9ae3d', '#5ac725', '#f56c6c', '#909399'],
				shopList: [],
				clouseId: undefined
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			clanceMethod(item) {
				console.log(item);
				this.showModal = true
				this.clouseId = item.lease_id
			},

			callAgent(item) {
				uni.makePhoneCall({
					phoneNumber: item.landlord_phone //仅为示例
				});
			},
			application(item) {
				// console.log(item,'啊啊啊');
				// return
				uni.navigateTo({
					url: '/pages/my/addInputlease/addInputlease?item=' + JSON.stringify(item),
					animationType: this.animation.type,
					animationDuration: this.animation.time
				})
			},
			changeList(str) {
				var labels = ""
				if (str) {
					labels = str.split(',')
				} else {
					labels = []
				}

				return labels
			},

            //获取角标数量（角标类型）
			async UnreadNum(informationType){
				//租约待确认列表未读数
				const res = await getUnreadNum(informationType);
				if (res.data.code != 200) return this.$refs.uToast.show({
					type: "error",
					message: res1.data.msg
				})
				//租约同意消息未读数
				if(informationType == 1){
					this.list[1].badge.value = res.data.data.count;
				}
				//租约已拒绝消息未读数
				if(informationType == 2){
					this.list[3].badge.value = res.data.data.count;
				}
			},
			async getList() {
				//获取基础列表
				const res = await agentgetConfirm({
					"communityName": "", //小区名称
					"leaseConfirmState": this.index
				});
				if (res.data.code != 200) return this.$refs.uToast.show({
					message: res.data.msg,
					type: 'error'
				})
				this.shopList = res.data.data
				//获取租约同意消息未读数
				this.UnreadNum(1)
				//获取租约已拒绝消息未读数
				this.UnreadNum(2)
				//用户点击已同意列表，把已同意列表未读的设置为已读
				if(this.index == 1){
					if(this.list[1].badge.value > 0){
						await haveRead({informationType: 1})
					}
				}
				//用户点击已拒绝列表，把已拒绝列表未读的设置为已读
				if(this.index == 3){
					if(this.list[3].badge.value > 0){
						await haveRead({informationType: 2})
					}
				}

			},
			async confirm() {
				const res = await putLease({
					"id":this.clouseId,
					"leaseConfirmState": "2"
				});
				if (res.data.code != 200) return this.$refs.uToast.show({
					message: res.data.msg,
					type: 'error'
				})
				this.showModal = false
				this.getList()
			},
			click(item) {
				this.index = item.index;
				this.getList()
			},
			detail(itemshop) {
				console.log(itemshop);
				uni.navigateTo({
					url: './lease/leaseDetail?id='+ itemshop.lease_id,
					animationType: this.animation.type,
					animationDuration: this.animation.time
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "~@/styles/index.scss";
	@import "~@/styles/global.scss";

	.pages {
		width: 100%;
		max-height: 100%;
		min-height: 100vh;

		// background-color: $pagebgc;
		.availabilityList {
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx;

			.tiem {
				// text-align: center;
				color: #7f7f7f;
				font-size: 24rpx;
				padding: 20rpx 0;
			}

			.shopList {
				border-radius: 10rpx;
				display: flex;
				// padding: 20rpx;
				margin-bottom: 20rpx;
				background-color: white;

				.description {
					width: 100%;
					margin-left: 20rpx;

					.title {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.description_title {
							font-weight: bold;
							font-size: 36rpx;
						}

						.titleType {
							font-weight: bold;
							font-size: 32rpx;
						}

						.success {
							color: #7f7f7f;
						}

						.error {
							color: #d02d37;
						}

						.primary {
							color: #79b8f4;
						}
					}

					.description_squaremetre {
						color: #000;
						font-size: 30rpx;
						// line-height: 60rpx;
						font-weight: bold;
						margin: 20rpx 0;
					}
				}

				.button_row {
					display: flex;

					.button_1 {
						border: 1rpx solid red;
						border-radius: 5rpx;
						padding: 3rpx 6rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 26rpx;
						color: red;
						margin-right: 5rpx;
					}

					.button_2 {
						border: 1rpx solid #7096dd;
						border-radius: 5rpx;
						padding: 3rpx 6rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 26rpx;
						color: #7096dd;
						margin-right: 5rpx;
					}

					.button_3 {
						border: 1rpx solid #efbd47;
						border-radius: 5rpx;
						padding: 3rpx 6rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 26rpx;
						color: #efbd47;
						margin-right: 5rpx;
					}
				}

				.row {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin: 5rpx 0;

					.money {
						font-weight: bold;
						font-size: 42rpx;
						color: red;
						display: flex;
						align-items: center;

						.unit {
							font-size: 28rpx;
						}
					}

					.buttom {
						display: flex;
						align-items: center;

						.custom-style {
							margin-left: 10rpx;
						}
					}

				}

			}
		}
	}
</style>